<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>AngularJS&middot;Hello AngularJS</title>
    <link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.css">
    <style>
        .demo{
            margin-bottom:10px;
            border-top:1px solid #1b926c;
        }
         footer{
             color:#fff;
             background-color: #222;
             border-color: #080808;
             padding-top:60px;
             margin-top:100px;
         }
    </style>
</head>
<body>
<div class="row">
    <nav class="navbar navbar-default navbar-static-top">
        <div class="container-fluid">
            <div class="navbar-header">
                <a class="navbar-brand" href="../index.html">首页</a>
            </div>
            <ul class="nav navbar-nav">
                <li class="active"><a href="javascript:void(0)">Link</a></li>
                <li><a href="javascript:void(0)">Link2</a></li>
            </ul>
        </div>
    </nav>
</div>
 <div class="container" ng-app="MyAPP">
     <siteheader></siteheader>
     <h3>Demo1: 指令示例</h3>
     <p>
         <input type="text" focus ng-model="user.name" class="form-control" placeholder="请输入用户名...">
         <span>{{user.name}}</span>
     </p>
     <br>
     <hello></hello>
     <br>
     <myimg></myimg>
     <br>
     <sitefooter></sitefooter>
 </div>
</body>
</html>
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.js" type="text/javascript"></script>
<script>
    var app=angular.module("MyAPP",[]);
    app.directive('focus', function() {
        return {
            link: function(scope, element, attrs) {
                element[0].focus();
            }
        };
    });

    app.directive('hello',function(){
        return {
            restrict: "E",
            replace: true,
            template: "<div class='row'>我是指令中的内容...</div>"
        }
    });
    app.directive('myimg', function () {
       return {
           restrict:"E",
           replace:true,
           templateUrl:"views/img_template.html"
       }
    });

     //公共部分，页头与页脚，封装到了指令中
    app.directive('siteheader',function(){
        return {
            restrict:"E",
            replace:true,
            templateUrl:"views/header.html"
        }
    });
    app.directive('sitefooter',function(){
        return {
            restrict:"E",
            replace:true,
            templateUrl:"views/footer.html"
        }
    });

</script>